﻿using FDSimpleModelGenerator.DapperAccessor;
using FDSimpleModelGenerator.IServices;
using Microsoft.Extensions.DependencyInjection;

namespace FDSimpleModelGenerator.Services.Sqlite
{
    public static class SqliteGeneratorExtensions
    {
        /// <summary>
        /// 使用Sqlite生成器
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddSqliteGenerator(this IServiceCollection services)
        {
            // 以防止多次注入DapperDbAccessor
            services.Remove(new ServiceDescriptor(typeof(IDbAccessor), typeof(DapperDbAccessor),
                ServiceLifetime.Transient));
            services.AddTransient<IDbAccessor, DapperDbAccessor>();
            services.AddTransient<IDbConfigResolver, SqliteDbConfigResolver>();
            services.AddSingleton<IGenerateModelService, GenerateModelSqliteService>();
            services.AddTransient<IDatabaseTableInfoService, SqliteDatabaseTableInfoService>();
            services.AddTransient<IGenerateTableService, SqliteGenerateTableService>();
            return services;
        }
    }
}
